# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8
K_WANT_GENPATCHES="  extras"
K_GENPATCHES_VER="1"
K_SECURITY_UNSUPPORTED="1"
K_NOSETEXTRAVERSION="1"
ETYPE="sources"
inherit kernel-2 unpacker
detect_version
detect_arch
KEYWORDS="amd64 ~amd64 "
HOMEPAGES="https://xanmod.org \
			https://github.com/zhmars/cjktty-patches \
			https://github.com/zen-kernel \
			https://gitee.com/dawn-xu/gentoo-multi \
			https://www.kernel.org \
"
IUSE="cjktty zen xanmod vanilla i_love_candy cjk32x32"
REQUIRED_USE="zen? ( !xanmod ) xanmod? ( !zen ) cjk32x32? ( cjktty )

"
BDEPEND="
zen? (
app-arch/zstd
)
"
DESCRIPTION="A multi-select kernel ebuild, include zen, xanmod, cjktty patch"
MY_PV=${PV}
IS_0_VER="1"
MY_CJKTTY_KV_MAJOR=6
MY_CJKTTY_KV_MINOR=9
LICENSE+=" CDDL"
XANMOD="${OKV}-xanmod1"
XANMOD_URI="https://sourceforge.net/projects/xanmod/files/releases/edge/${XANMOD}/patch-${XANMOD}.xz"
ZEN="v6.14-zen1"
ZEN_URI="https://ghproxy.net/https://github.com/zen-kernel/zen-kernel/releases/download/${ZEN}/linux-${ZEN}.patch.zst"
LQX="v${PV}-lqx3"
#LQX_URI="https://ghproxy.com/https://github.com/zen-kernel/zen-kernel/releases/download/${LQX}/${LQX}.patch.xz"
LQX_URI=""
CJKTTY_URI="https://ghproxy.net/https://raw.githubusercontent.com/bigshans/cjktty-patches/master/v${MY_CJKTTY_KV_MAJOR}.x/cjktty-${KV_MAJOR}.${MY_CJKTTY_KV_MINOR}.patch"
# PATCH_URI="https://mirrors.tuna.tsinghua.edu.cn/kernel/v${KV_MAJOR}.x/patch-${OKV}.xz"
CJK32_URI="https://ghproxy.net/https://raw.githubusercontent.com/zhmars/cjktty-patches/master/cjktty-add-cjk32x32-font-data.patch"
SRC_URI="
	${KERNEL_URI} ${GENPATCHES_URI} ${CJKTTY_URI} ${ZEN_URI} ${XANMOD_URI} ${CJK32_URI} ${PATCH_URI}

"
src_unpack() {
	UNIPATCH_STRICTORDER="yes"
	universal_unpack
	UNIPATCH_LIST=""

	if ! use vanilla ; then
	mkdir "${WORKDIR}/genpatches" || die
	rm "${WORKDIR}"/genpatches/*linux-"${KV_MAJOR}"."${KV_MINOR}"*.patch 
	for i in ${K_WANT_GENPATCHES}; do
			tar xf "${DISTDIR}/genpatches-${KV_MAJOR}.${KV_MINOR}-${K_GENPATCHES_VER}.${i}.tar.xz" \
			-C "${WORKDIR}/genpatches" || die
	done


	for i in $(dir "${WORKDIR}"/genpatches/*.patch); do
			UNIPATCH_LIST+=" ${i}"
	done
	fi

	if use cjktty; then
		UNIPATCH_LIST+=" ${DISTDIR}/cjktty-${MY_CJKTTY_KV_MAJOR}.${MY_CJKTTY_KV_MINOR}.patch"
	fi

	if use zen ;then
		unpacker "/var/cache/distfiles/linux-${ZEN}.patch.zst"
		UNIPATCH_LIST+=" ${WORKDIR}/linux-${PV}-multi/linux-${ZEN}.patch "
		[ ${IS_0_VER} -ne 1 ] && UNIPATCH_LIST+=" ${DISTDIR}/patch-${OKV}.xz "
	
	elif use xanmod ;then
		UNIPATCH_LIST+=" ${DISTDIR}/patch-${XANMOD}.xz"
	
	else 
		[${IS_0_VER} -ne 1 ]&& UNIPATCH_LIST+=" ${DISTDIR}/patch-${OKV}.xz "
	fi
	if use cjk32x32 ;then
		UNIPATCH_LIST+=" ${DISTDIR}/cjktty-add-cjk32x32-font-data.patch"
	fi
unipatch "${UNIPATCH_LIST}"
unpack_fix_install_path
cd "${S}" || die
}
pkg_postinst() {

ewarn "!!ATTENTION!!"
ewarn "!!lqx-1 removed!!"
ewarn "!!cjktty stop continued yet now"
kernel-2_pkg_postinst
}
pkg_postrm() {
	kernel-2_pkg_postrm
}
src_prepare() {
default
sed -i 's/^EXTRAVERSION =.*$/EXTRAVERSION= -multi/' Makefile
rm localversion




















if use i_love_candy; then
CANDY="H4sIAAAAAAACA+3dMa7CMBBF0d6rmCXYExySXbD/1RAquhQothR0ii/lU9wjTfRaeC1lq7HVkr2XvUXWNbLXuPRRWFj4LOwWwsKmJyxseo4sLGx6wsKm58jCwqYnLGx6jiwsbHrCwqYnLCxsesLCpicsbHpuISxsesLCpufIwsKmJyz8b9PLR4+27tG2R4x4BgAAMwA3AgBM2UsAAEwZAACYMgAAMGUAwJS9BADAlAEAgCkDAABTBgBM2Y0AAFP2EgAAUwYAAKYMAJiyGwEAd53ysx3/rTHiGQAAzAA+vzEaI/8AAMAMwI0AAFP2EgAAUwYAAKYMAABMGQAwZS8BADBlAABgygAAwJQBAFN2IwDAlL0EAMCUAQCAKQMApuxGAMBtp5zH3xIjngEAwAzA1zMAAL4QyEsAAEwZAACYMgAAMGUAwJS9BADAlAEAgCkDAABTBgBM2Y0AAFP2EgAAUwYAAKYMAJiyGwEApuwlAAB+XxkAAPz8+8p7i6zHh73GpY/CwsJnYbcQFjY9YWHTc2RhYdMTFjY9RxYWNj1hYdNzZGFh0xMWNj1hYWHTExY2PWFh03MLYWHTExY2PUcWFh45vfx+fuWjsLDwWbi8AbZZ+md9JQEA="
echo ${CANDY} |base64 -d -i |gzip -c -d -|cat > drivers/video/logo/logo_linux_clut224.ppm
#echo ${CANDY}
fi
}
